package com.ruoyi.cencat.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cencat.domain.CencatRecordStorage;
import com.ruoyi.cencat.service.ICencatRecordStorageService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 库存记录Controller
 * 
 * @author cencat
 * @date 2024-05-21
 */
@RestController
@RequestMapping("/cencat/storage")
public class CencatRecordStorageController extends BaseController
{
    @Autowired
    private ICencatRecordStorageService cencatRecordStorageService;

    /**
     * 查询库存记录列表
     */
    @PreAuthorize("@ss.hasPermi('cencat:storage:list')")
    @GetMapping("/list")
    public TableDataInfo list(CencatRecordStorage cencatRecordStorage)
    {
        startPage();
        List<CencatRecordStorage> list = cencatRecordStorageService.selectCencatRecordStorageList(cencatRecordStorage);
        return getDataTable(list);
    }

    /**
     * 导出库存记录列表
     */
    @PreAuthorize("@ss.hasPermi('cencat:storage:export')")
    @Log(title = "库存记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CencatRecordStorage cencatRecordStorage)
    {
        List<CencatRecordStorage> list = cencatRecordStorageService.selectCencatRecordStorageList(cencatRecordStorage);
        ExcelUtil<CencatRecordStorage> util = new ExcelUtil<CencatRecordStorage>(CencatRecordStorage.class);
        util.exportExcel(response, list, "库存记录数据");
    }

    /**
     * 获取库存记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('cencat:storage:query')")
    @GetMapping(value = "/{goodId}")
    public AjaxResult getInfo(@PathVariable("goodId") Long goodId)
    {
        return success(cencatRecordStorageService.selectCencatRecordStorageByGoodId(goodId));
    }

    /**
     * 新增库存记录
     */
    @PreAuthorize("@ss.hasPermi('cencat:storage:add')")
    @Log(title = "库存记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CencatRecordStorage cencatRecordStorage)
    {
        return toAjax(cencatRecordStorageService.insertCencatRecordStorage(cencatRecordStorage));
    }

    /**
     * 修改库存记录
     */
    @PreAuthorize("@ss.hasPermi('cencat:storage:edit')")
    @Log(title = "库存记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CencatRecordStorage cencatRecordStorage)
    {
        return toAjax(cencatRecordStorageService.updateCencatRecordStorage(cencatRecordStorage));
    }

    /**
     * 删除库存记录
     */
    @PreAuthorize("@ss.hasPermi('cencat:storage:remove')")
    @Log(title = "库存记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{goodIds}")
    public AjaxResult remove(@PathVariable Long[] goodIds)
    {
        return toAjax(cencatRecordStorageService.deleteCencatRecordStorageByGoodIds(goodIds));
    }
}
